# _*_ coding:utf-8 _*_
# @File  : price_postion.py
# @Time  : 2021-11-19  11:19
# @Author: zizle

# 指数持仓

from fastapi import APIRouter, Path, Body
from db import utils as dbutils
from db import FAConnection
from status import r_status

price_position_api = APIRouter()


# 修改指数持仓的数据
@price_position_api.put('/{pp_id}/', summary='修改指数持仓的数据')
async def modify_price_position(pp_id: int = Path(...), body_data: dict = Body(...)):
    accept_columns = ['close_price', 'position_price', 'position_volume', 'long_position', 'short_position']
    db = FAConnection(conn_name='修改指数持仓数据')
    modify_item = dbutils.exclude_columns(body_data, accept_columns)
    middle_sql = dbutils.create_sql(modify_item)
    sql = 'UPDATE dat_futures_price_position SET ' + middle_sql + 'WHERE id=%(id)s LIMIT 1;'
    modify_item['id'] = pp_id
    _, success = db.execute(sql, param=modify_item)
    if success:
        return {'code': r_status.SUCCESS, 'message': '修改数据成功!'}
    return {'code': r_status.SERVER_ERROR, 'message': '修改数据失败!'}

